package com.example.demo.controller;
import com.example.demo.Common.CommonIT;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.demo.annotation.AuthToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.Excel.ExcelUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xc.roadRisk.common.config.SwaggerAutoConfig;
import com.xc.roadRisk.common.utils.ResponseUtils;
import com.xc.roadRisk.common.vo.Response;
import com.xc.roadRisk.common.vo.PageList;

import java.util.Date;
import java.util.List;
import com.example.demo.entity.Status_changes;
import com.example.demo.service.IStatus_changesService;

 /**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hanfei
 * @since 2021-05-13
 */
@Api(value = "状态更新",tags = "状态更新")
@RestController
public class Status_changesController {
    @Autowired
    private IStatus_changesService status_changesApi;
    @AuthToken
    @ApiOperation("创建单个Status_changes")
    @ApiImplicitParam(name = "version", paramType = "path")
    @PostMapping("pv/status_changess")
    public Response<Boolean> insert(@RequestBody Status_changes status_changes) {
        CommonIT commonIT=new CommonIT();
        String id=commonIT.findId();
        status_changes.setStatus_id(id);
        status_changes.setCreate_time(new Date());
        Response<Boolean> response=ResponseUtils.returnObjectSuccess(status_changesApi.insert(status_changes));
        response.setMsg(id);
        return response;
    }
    @AuthToken
    @ApiOperation("编辑单个Status_changes")
    @ApiImplicitParam(name = "version", paramType = "path")
    @PutMapping("pv/status_changess/{uid}")
    public Response<Boolean> updateById(@PathVariable("uid") String uid, @RequestBody Status_changes status_changes) {
        status_changes.setStatus_id(uid);
        CommonIT commonIT=new CommonIT();
     status_changes.setUpdate_time(new Date());
        return ResponseUtils.returnObjectSuccess(status_changesApi.updateById(status_changes));
    }
    @AuthToken
    @ApiOperation("查询单个Status_changes")
    @ApiImplicitParam(name = "version", paramType = "path")
    @GetMapping("pb/status_changess/{uid}")
    public Response<Status_changes> selectById(@PathVariable("uid") String uid) {
        return ResponseUtils.returnObjectSuccess(status_changesApi.selectById(uid));
    }

    @AuthToken
    @ApiOperation("查询所有")
    @ApiImplicitParam(name = "version", paramType = "path")
    @GetMapping("pb/status_changess/findall")
    public Response<List<Status_changes>> findall(Status_changes status_changes) {
        return ResponseUtils.returnObjectSuccess(status_changesApi.selectList(new EntityWrapper<>(status_changes)));
        }
     @AuthToken
    @ApiOperation("导出")
    @GetMapping("/status_changess/export")
    public String exportAll(HttpServletResponse response,Status_changes status_changes) {
        List<Status_changes> list=status_changesApi.selectList(new EntityWrapper<>(status_changes));
        ExcelUtils.writeExcel(response,list,Status_changes.class);
        return null;
        }
    @AuthToken
    @ApiOperation("导入")
    @PostMapping("/status_changess/import")
    public Response importAll(@RequestParam("file")MultipartFile file){
        List<Status_changes> list=ExcelUtils.readExcel(null,Status_changes.class,file);
        for(Status_changes a:list){
        CommonIT commonIT=new CommonIT();
        String id=commonIT.findId();
        a.setStatus_id(id);
        a.setCreate_time(new Date());
        }

        return ResponseUtils.returnObjectSuccess(status_changesApi.insertBatch(list));
        }
    @AuthToken
    @ApiOperation("删除单个Status_changes")
    @ApiImplicitParam(name = "version", paramType = "path")
    @DeleteMapping("delete/status_changess/{uid}")
    public Response<Boolean> deleteById(@PathVariable("uid") String uid) {

        return ResponseUtils.returnObjectSuccess(status_changesApi.deleteById(uid));
        }
        @AuthToken
        @ApiOperation("模糊查询加定向查询分页")
        @ApiImplicitParam(name = "version", paramType = "path")
        @GetMapping("pb/status_changess/action/findByKeyAndAll")
        public Response<PageList<Status_changes>> findByKeyAndAll(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
            @RequestParam(value = "key",required = false) String key,
              Status_changes entity) {
        Page<Status_changes> page = status_changesApi.findByKeyAndAll(new Page<>(pageNo, pageSize), key,entity);
        return ResponseUtils.returnObjectSuccess(new PageList<>(page));
        }
}
